package controller.base;

import domain.entity.base.UserInfo;
import domain.service.base.UserInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by bowen on 2017-08-18.
 */
@Controller
public class UserInfoController {

    private static final Logger logger = LoggerFactory.getLogger(UserInfoController.class);

    @Autowired
    private UserInfoService userInfoService;

    @RequestMapping(value = "getEventUsers")
    @ResponseBody
    public List<UserInfo> getEventUsers() {
        return userInfoService.getEventUsers();
    }


    /**
     * 事件上报用户配置页面初始化数据
     *
     * @return
     */
    @RequestMapping(value = "getUserCheck")
    @ResponseBody
    public List<UserInfo> getUserCheck(HttpServletResponse response) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        return userInfoService.getUserCheck();
    }

    /**
     * 事件上报用户配置保存方法
     *
     * @param eventIds
     * @param adminIds
     * @return
     */
    @RequestMapping(value = "addEventUsers", method = RequestMethod.POST)
    @ResponseBody
    public String addEventUsers(HttpServletResponse response, String eventIds, String adminIds) {
        response.setHeader("Access-Control-Allow-Origin", "*");
        userInfoService.addEventUsers(eventIds, adminIds);
        return "保存成功！";
    }

}
